package com.yunqiao.admin.modules.api.controller;

import com.yunqiao.common.utils.PageUtils;
import com.yunqiao.common.utils.R;
import com.yunqiao.service.api.UserDepositService;
import com.yunqiao.service.api.entity.UserDepositEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 退押金申请
 *
 * @author Crocutax
 * @email wangxw725@163.com
 * @date 2019-03-15 14:07:30
 */
@RestController
@RequestMapping("api/userdeposit")
public class UserDepositController {

    @Autowired
    private UserDepositService userDepositService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("api:userdeposit:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = userDepositService.queryPage(params);
        return R.ok().put("page", page);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("api:userdeposit:info")
    public R info(@PathVariable("id") Long id){
        UserDepositEntity userDeposit = userDepositService.getById(id);
        return R.ok().put("userDeposit", userDeposit);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("api:userdeposit:save")
    public R save(@RequestBody UserDepositEntity userDeposit){
        userDepositService.save(userDeposit);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("api:userdeposit:update")
    public R update(@RequestBody UserDepositEntity userDeposit){
        userDepositService.updateById(userDeposit);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("api:userdeposit:delete")
    public R delete(@RequestBody Long[] ids){
        userDepositService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

    /**
     * 同意退款
     */
    @PostMapping("/agent/{id}")
    @RequiresPermissions("api:userdeposit:agent")
    public R agent(@PathVariable Long id) throws Exception {
        return R.ok().put("msg",userDepositService.agent(id));
    }

    /**
     * 拒绝退款
     */
    @PostMapping("/refuse")
    @RequiresPermissions("api:userdeposit:refuse")
    public R refuse(@RequestBody UserDepositEntity userDepositEntity){
        userDepositService.refuse(userDepositEntity);
        return R.ok();
    }
}
